﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls"
                    xmlns:converters="clr-namespace:MahApps.Metro.Converters">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/VS/Colors.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <converters:ThicknessToDoubleConverter x:Key="ThicknessToDoubleConverter" />

    <Style TargetType="{x:Type Controls:NumericUpDown}">
        <Setter Property="BorderThickness"
                Value="1" />
        <Setter Property="SnapsToDevicePixels"
                Value="true" />
        <Setter Property="Foreground"
                Value="{DynamicResource TextBrush}" />
        <Setter Property="BorderBrush"
                Value="{DynamicResource TextBoxBorderBrush}" />
        <Setter Property="Controls:ControlsHelper.FocusBorderBrush"
                Value="{DynamicResource TextBoxFocusBorderBrush}" />
        <Setter Property="Controls:ControlsHelper.MouseOverBorderBrush"
                Value="{DynamicResource TextBoxMouseOverBorderBrush}" />
        <Setter Property="VerticalAlignment"
                Value="Center" />
        <Setter Property="FontFamily"
                Value="{DynamicResource ContentFontFamily}" />
        <Setter Property="FontSize"
                Value="{DynamicResource ContentFontSize}" />
        <Setter Property="Controls:TextBoxHelper.IsMonitoring"
                Value="True" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="MinHeight"
                Value="26" />
        <Setter Property="MinWidth"
                Value="62" />
        <Setter Property="Background"
                Value="{DynamicResource ControlBackgroundBrush}" />
        <Setter Property="Validation.ErrorTemplate"
                Value="{DynamicResource ValidationErrorTemplate}" />
        <Setter Property="FocusVisualStyle"
                Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:NumericUpDown}">
                    <Grid Height="{TemplateBinding Height}"
                          MinHeight="{TemplateBinding MinHeight}"
                          MaxHeight="{TemplateBinding MaxHeight}"
                          Margin="{TemplateBinding Padding}"
                          VerticalAlignment="{TemplateBinding VerticalAlignment}"
                          Background="{TemplateBinding Background}">
                        <Border x:Name="Base"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{TemplateBinding Background}" />
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition x:Name="PART_TextBoxColumn"
                                                  Width="*" />
                                <ColumnDefinition x:Name="PART_NumericUpColumn"
                                                  Width="Auto" />
                                <ColumnDefinition x:Name="PART_NumericDownColumn"
                                                  Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <TextBox x:Name="PART_TextBox"
                                     Controls:ControlsHelper.DisabledVisualElementVisibility="Collapsed"
                                     MinWidth="20"
                                     MinHeight="{TemplateBinding MinHeight}"
                                     Foreground="{TemplateBinding Foreground}"
                                     HorizontalAlignment="Stretch"
                                     HorizontalContentAlignment="Right"
                                     VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                     SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                     BorderThickness="0"
                                     Background="{x:Null}"
                                     Focusable="{TemplateBinding Focusable}"
                                     HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                     VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                     IsReadOnly="{TemplateBinding IsReadOnly}"
                                     FontFamily="{TemplateBinding FontFamily}"
                                     FontSize="{TemplateBinding FontSize}"
                                     Controls:TextBoxHelper.ClearTextButton="{TemplateBinding Controls:TextBoxHelper.ClearTextButton}"
                                     Controls:TextBoxHelper.Watermark="{TemplateBinding Controls:TextBoxHelper.Watermark}"
                                     Controls:TextBoxHelper.ButtonsAlignment="{TemplateBinding ButtonsAlignment}" />
                            <RepeatButton x:Name="PART_NumericUp"
                                          Grid.Column="1"
                                          Margin="2,2,0,2"
                                          Delay="{TemplateBinding Delay}"
                                          Foreground="{TemplateBinding Foreground}"
                                          Style="{DynamicResource ChromelessButtonStyle}"
                                          IsTabStop="False"
                                          Width="{TemplateBinding UpDownButtonsWidth}">
                                <Path x:Name="PolygonUp"
                                      Width="14"
                                      Height="14"
                                      Stretch="Fill"
                                      Fill="{DynamicResource GrayBrush1}"
                                      Data="F1 M 35,19L 41,19L 41,35L 57,35L 57,41L 41,41L 41,57L 35,57L 35,41L 19,41L 19,35L 35,35L 35,19 Z " />
                            </RepeatButton>
                            <RepeatButton x:Name="PART_NumericDown"
                                          Grid.Column="2"
                                          Margin="0,2,2,2"
                                          VerticalContentAlignment="Center"
                                          Delay="{TemplateBinding Delay}"
                                          Style="{DynamicResource ChromelessButtonStyle}"
                                          Foreground="{TemplateBinding Foreground}"
                                          IsTabStop="False"
                                          Width="{TemplateBinding UpDownButtonsWidth}">
                                <Path x:Name="PolygonDown"
                                      Width="14"
                                      Height="3"
                                      Stretch="Fill"
                                      Fill="{DynamicResource GrayBrush1}"
                                      Data="F1 M 19,38L 57,38L 57,44L 19,44L 19,38 Z " />
                            </RepeatButton>
                        </Grid>
                        <Border x:Name="DisabledVisualElement"
                                Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.DisabledVisualElementVisibility), Mode=OneWay}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                BorderBrush="{DynamicResource ControlsDisabledBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{DynamicResource ControlsDisabledBrush}"
                                IsHitTestVisible="False"
                                Opacity="0" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="ButtonsAlignment"
                                 Value="Left">
                            <Setter TargetName="PART_TextBox"
                                    Property="Grid.Column"
                                    Value="2" />
                            <Setter TargetName="PART_NumericDown"
                                    Property="Grid.Column"
                                    Value="1" />
                            <Setter TargetName="PART_NumericDown"
                                    Property="Margin"
                                    Value="0,2,2,2" />
                            <Setter TargetName="PART_NumericUp"
                                    Property="Margin"
                                    Value="2,2,0,2" />
                            <Setter TargetName="PART_NumericUp"
                                    Property="Grid.Column"
                                    Value="0" />
                            <Setter TargetName="PART_NumericDownColumn"
                                    Property="Width"
                                    Value="*" />
                            <Setter TargetName="PART_NumericUpColumn"
                                    Property="Width"
                                    Value="Auto" />
                            <Setter TargetName="PART_TextBoxColumn"
                                    Property="Width"
                                    Value="Auto" />
                        </Trigger>
                        <Trigger Property="IsEnabled"
                                 Value="False">
                            <Setter TargetName="DisabledVisualElement"
                                    Property="Opacity"
                                    Value="0.6" />
                        </Trigger>
                        <Trigger Property="IsReadOnly"
                                 Value="True">
                            <Setter TargetName="PART_NumericUp"
                                    Property="IsEnabled"
                                    Value="False" />
                            <Setter TargetName="PART_NumericDown"
                                    Property="IsEnabled"
                                    Value="False" />
                            <Setter Property="InterceptArrowKeys"
                                    Value="False" />
                            <Setter Property="InterceptMouseWheel"
                                    Value="False" />
                            <Setter Property="InterceptManualEnter"
                                    Value="False" />
                        </Trigger>
                        <Trigger Property="IsMouseOver"
                                 Value="True"
                                 SourceName="PART_NumericUp">
                            <Setter TargetName="PART_NumericUp"
                                    Property="Background"
                                    Value="{DynamicResource GrayBrush8}" />
                            <Setter TargetName="PolygonUp"
                                    Property="Fill"
                                    Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                        <Trigger Property="IsPressed"
                                 Value="True"
                                 SourceName="PART_NumericUp">
                            <Setter TargetName="PART_NumericUp"
                                    Property="Background"
                                    Value="{DynamicResource BlackBrush}" />
                            <Setter TargetName="PolygonUp"
                                    Property="Fill"
                                    Value="{DynamicResource WhiteBrush}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver"
                                 Value="True"
                                 SourceName="PART_NumericDown">
                            <Setter TargetName="PART_NumericDown"
                                    Property="Background"
                                    Value="{DynamicResource GrayBrush8}" />
                            <Setter TargetName="PolygonDown"
                                    Property="Fill"
                                    Value="{DynamicResource AccentColorBrush}" />
                        </Trigger>
                        <Trigger Property="IsPressed"
                                 Value="True"
                                 SourceName="PART_NumericDown">
                            <Setter TargetName="PART_NumericDown"
                                    Property="Background"
                                    Value="{DynamicResource BlackBrush}" />
                            <Setter TargetName="PolygonDown"
                                    Property="Fill"
                                    Value="{DynamicResource WhiteBrush}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver"
                                 Value="true">
                            <Setter TargetName="Base"
                                    Property="BorderBrush"
                                    Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.MouseOverBorderBrush)}" />
                        </Trigger>
                        <Trigger Property="IsFocused"
                                 Value="true"
                                 SourceName="PART_TextBox">
                            <Setter TargetName="Base"
                                    Property="BorderBrush"
                                    Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderBrush)}" />
                        </Trigger>

                        <Trigger Property="HideUpDownButtons"
                                 Value="True">
                            <Setter TargetName="PART_NumericUp"
                                    Property="Visibility"
                                    Value="Collapsed" />
                            <Setter TargetName="PART_NumericDown"
                                    Property="Visibility"
                                    Value="Collapsed" />
                            <Setter TargetName="PART_NumericUpColumn"
                                    Property="Width"
                                    Value="0" />
                            <Setter TargetName="PART_NumericDownColumn"
                                    Property="Width"
                                    Value="0" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>